home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / System 7.0 Samples / ProcDoggie 1.0a6 / UProcessLDEF.inc1.p < prev    next >
Encoding:
Text File  |  1991-02-07  |  5.1 KB  |  160 lines  |  [TEXT/MPS ]

  1. {-------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    Code for process-list LDEF
  6. #
  7. #    Program:    ProcDoggie
  8. #    File:        UProcessLDEF.inc1.p - Pascal Implementation
  9. #
  10. #    by:        Forrest Tanaka
  11. #
  12. #    Copyright © 1988-1991 Apple Computer, Inc.
  13. #    All rights reserved.
  14. #
  15. -------------------------------------------------------------------------------}
  16. {[j=20/57/1$] Pasmat Options}
  17. {$R-}
  18.  
  19.  
  20.     CONST
  21.         kCellMargin = 3; {Margin between list contents and list edge in pixels}
  22.  
  23.  
  24.     PROCEDURE DrawCell (cellRect: Rect; theCell: Cell; selected: Boolean;
  25.             theList: ListHandle; dataOffset: Integer);
  26.         FORWARD;
  27.     PROCEDURE HilightCell (cellRect: Rect);
  28.         FORWARD;
  29.  
  30.  
  31. {$S Main}
  32. (*******************************************************************************
  33. * Public: ProcessList
  34. *
  35. * Here’s the entry point to my custom LDEF.  Yup.
  36. *******************************************************************************)
  37.  
  38.     PROCEDURE ProcessList (message:    Integer;
  39.                            selectCell: Boolean;
  40.                            cellRect:   Rect;
  41.                            theCell:    Cell;
  42.                            dataOffset: Integer;
  43.                            dataLength: Integer;
  44.                            theList:    ListHandle);
  45.  
  46.     BEGIN
  47.         IF message = lDrawMsg THEN
  48.             BEGIN
  49.                 IF dataLength > 0 THEN
  50.                     DrawCell (cellRect, theCell, selectCell, theList, dataOffset)
  51.             END
  52.         ELSE IF message = lHiliteMsg THEN
  53.             HilightCell (cellRect)
  54.     END;
  55.  
  56.  
  57. {$S Main}
  58. (*******************************************************************************
  59. * Private: DrawCell - Draw the contents of the specified cell
  60. *
  61. * This routine draws the contents of the cell specified by theCell into it’s
  62. * rectangle, which is specified by cellRect.  In case the font is too large for
  63. * the cell rectangle, I set the clip region to cellRect before drawing the cell
  64. * text, then set it back to what it was afterwards.
  65. *
  66. * If selected is TRUE, then theCell is selected.  In that case, my HilightCell
  67. * routine is called to hilight the cell.
  68. *
  69. * The list that this all takes place in is specified by theList.
  70. *******************************************************************************)
  71.  
  72.     PROCEDURE DrawCell (cellRect:   Rect;
  73.                         theCell:    Cell;
  74.                         selected:   Boolean;
  75.                         theList:    ListHandle;
  76.                         dataOffset: Integer);
  77.  
  78.         VAR
  79.             cellInfo:   ProcessListInfoRec; {Information for cell to be drawn}
  80.             currClip:   RgnHandle;          {Handle to the current clip region}
  81.             currPen:    PenState;           {Current pen characteristics}
  82.             currFont:   FontInfo;           {Current font characteristics}
  83.             dataLen:    Integer;            {Length of cell data in bytes}
  84.             marginRect: Rect;               {Rect that process name is drawn into}
  85.             alignment:  Integer;            {Alignment of process name text}
  86.             spareSpace: Integer;            {marginRect width - text width}
  87.  
  88.     BEGIN
  89.         (* Save the current pen state and set the default pen characteristics *)
  90.         GetPenState ((*<*)currPen);
  91.         PenNormal;
  92.  
  93.         (* Save the current clip region and set it to cellRect *)
  94.         currClip := NewRgn;
  95.         GetClip ((*<*)currClip);
  96.         ClipRect (cellRect);
  97.  
  98.         (* Will draw text into the cell rect with a margin on left and right *)
  99.         marginRect := cellRect;
  100.         InsetRect ((*◊*)marginRect, kCellMargin, 0);
  101.  
  102.         (* Get the information for the specified cell *)
  103.         dataLen := SIZEOF (ProcessListInfoRec);
  104.         LGetCell ((*<*)Ptr(@cellInfo), (*◊*)dataLen, theCell, theList);
  105.  
  106.         (* To find where to draw the cell’s text, get current font information *)
  107.         GetFontInfo ((*<*)currFont);
  108.  
  109.         (* Position the pen for drawing the text *)
  110.         MoveTo (marginRect.left, marginRect.top + currFont.ascent);
  111.  
  112.         (* Determine whether system script is left-to-right or right-to-left *)
  113.         IF GetSysJust = 0 THEN
  114.             alignment := teFlushLeft
  115.         ELSE
  116.             alignment := teFlushRight;
  117.  
  118.         (* Adjust the pen for right-aligned text if script is right-to-left *)
  119.         IF alignment = teFlushRight THEN
  120.             BEGIN
  121.                 spareSpace := marginRect.right - marginRect.left -
  122.                         StringWidth (cellInfo.processName);
  123.                 Move (spareSpace, 0);
  124.             END;
  125.  
  126.         (* Draw the cell’s contents *)
  127.         EraseRect (cellRect);
  128.         DrawString (cellInfo.processName);
  129.  
  130.         (* If the cell is selected, hilight it *)
  131.         IF selected THEN
  132.             HilightCell (cellRect);
  133.  
  134.         (* Restore the current clip region and pen *)
  135.         SetClip (currClip);
  136.         DisposeRgn (currClip);
  137.         SetPenState (currPen);
  138.     END;
  139.  
  140.  
  141. {$S Main}
  142. (*******************************************************************************
  143. * Private: HilightCell - Hilight the specified cell
  144. *
  145. * This routine hilights the cell whose rectangle is cellRect.  I also clear the
  146. * hilight bit of the HiliteMode low-memory global.  If this is running on a
  147. * Color QuickDraw machine, then background hilighting is done instead of
  148. * the usual inversion.
  149. *******************************************************************************)
  150.  
  151.     PROCEDURE HilightCell (cellRect: Rect);
  152.  
  153.     BEGIN
  154.         (* Do the fancy, new kind of hilighting on a Color QuickDraw Mac *)
  155.         BitClr (Ptr(HiliteMode), pHiliteBit);
  156.  
  157.         (* Now, hilight the cell *)
  158.         InvertRect (cellRect)
  159.     END;
  160.